<template>
  <div>
    <el-card>
      <CategorySelector :disabled="showState !== 1"></CategorySelector>
    </el-card>

    <el-card style="margin-top: 20px">
      <SpuList v-if="showState === 1" @changeState="changeState"></SpuList>
      <SpuForm v-if="showState === 2" :spu="spu" @changeState="changeState"></SpuForm>
      <SkuForm v-if="showState === 3" :spu="spu" @changeState="changeState"></SkuForm>
    </el-card>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  name: "Spu", //组件名称
});
</script>
<script lang="ts" setup>
import { ref } from "vue";
import SpuList from "./components/SpuList/index.vue";
import SpuForm from "./components/SpuForm/index.vue";
import SkuForm from "./components/SkuForm/index.vue";
import type { SpuData } from "@/api/spu";

const showState = ref(1); //1:spu列表  2:spuForm  3:skuForm

// 这个就是后期我们要收集的spuForm原形
// 添加的时候传递给spuForm去收集,没有id
// 修改的时候传递给spuForm去收集,有id
const spu = ref<SpuData>({
  spuName: "",
  description: "",
  category3Id: "",
  tmId: "",
  spuSaleAttrList: [],
  spuImageList: [],
});

const changeState = (state: number, row: SpuData) => {
  showState.value = state;
  if (row) {
    // 修改或者添加sku
    spu.value = row;
  } else {
    // 添加spu
    spu.value = {
      spuName: "",
      description: "",
      category3Id: "",
      tmId: "",
      spuSaleAttrList: [],
      spuImageList: [],
    };
  }
};
</script>

<style lang="scss" scoped></style>